#!/bin/bash
source src/conf/config.conf

cd $tftp_dir

mirrorlenny=http://archive.debian.org/debian/dists/
mirror=http://ftp.nl.debian.org/debian/dists


echo " Downloading Debian Etch..."

wget -c -q $mirrorlenny/etch/main/installer-i386/current/images/netboot/netboot.tar.gz -O debian-etch-i386.tar.gz
wget -c -q $mirrorlenny/etch/main/installer-amd64/current/images/netboot/netboot.tar.gz -O debian-etch-amd64.tar.gz
wget -c -q $mirrorlenny/etch/main/installer-ia64/current/images/netboot/netboot.tar.gz -O debian-etch-ia64.tar.gz

echo " Downloading Debian Sarge..."

wget -c -q $mirrorlenny/sarge/main/installer-ia64/current/images/netboot/netboot.tar.gz -O debian-sarge-ia64.tar.gz
wget -c -q $mirrorlenny/sarge/main/installer-i386/current/images/netboot/netboot.tar.gz -O debian-sarge-i386.tar.gz

echo " Downloading Debian Lenny..."

wget -c -q $mirrorlenny/lenny/main/installer-i386/current/images/netboot/netboot.tar.gz -O debian-lenny-i386.tar.gz
wget -c -q $mirrorlenny/lenny/main/installer-amd64/current/images/netboot/netboot.tar.gz -O debian-lenny-amd64.tar.gz 
wget -c -q $mirror/lenny/main/installer-ia64/current/images/netboot/netboot.tar.gz -O debian-lenny-ia64.tar.gz

echo " Downloading Debian Wheezy..."

wget -c -q $mirror/wheezy/main/installer-ia64/current/images/netboot/netboot.tar.gz -O debian-wheezy-ia64.tar.gz
wget -c -q $mirror/wheezy/main/installer-i386/current/images/netboot/netboot.tar.gz -O debian-wheezy-i386.tar.gz
wget -c -q $mirror/wheezy/main/installer-amd64/current/images/netboot/netboot.tar.gz -O debian-wheezy-amd64.tar.gz
echo " Downloading Debian Squeeze..."

wget -c -q $mirror/squeeze/main/installer-ia64/current/images/netboot/netboot.tar.gz -O debian-squeeze-ia64.tar.gz
wget -c -q $mirror/squeeze/main/installer-i386/current/images/netboot/netboot.tar.gz -O debian-squeeze-i386.tar.gz
wget -c -q $mirror/squeeze/main/installer-amd64/current/images/netboot/netboot.tar.gz -O debian-squeeze-amd64.tar.gz




for DIST in wheezy lenny sarge etch squeeze; do
    mkdir -p "./_debian-installer/${DIST}"
    for ARCH in i386 amd64 ia64; do
        tar -xzvf "debian-${DIST}-${ARCH}".tar.gz ./debian-installer/
mv "./debian-installer/${ARCH}/" "./_debian-installer/${DIST}/"



done
done

 rm -r ./debian-installer/
mkdir tars
mv debian*.tar.gz tars/
yes | cp -Rv _debian-installer/* LINUX/debian/
rm -r _debian-installer



for DIST in wheezy squeeze; do
       mkdir -p "power/${DIST}"

    for ARCH in powerpc powerpc64; do
       mkdir -p "power/${DIST}/${ARCH}"
 
 done
 done
cd power/


wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc/netboot/vmlinux && mv vmlinux wheezy/powerpc
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc/netboot/yaboot && mv yaboot wheezy/powerpc
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc/netboot/initrd.gz && mv initrd.gz wheezy/powerpc
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc/netboot/yaboot.conf && mv yaboot.conf wheezy/powerpc
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc/netboot/boot.msg && mv boot.msg wheezy/powerpc
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc/netboot/vmlinux && mv vmlinux squeeze/powerpc
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc/netboot/yaboot && mv yaboot squeeze/powerpc
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc/netboot/initrd.gz && mv initrd.gz squeeze/powerpc
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc/netboot/yaboot.conf && mv yaboot.conf squeeze/powerpc
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc/netboot/boot.msg  && mv boot.msg squeeze/powerpc


wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc64/netboot/vmlinux && mv vmlinux wheezy/powerpc64
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc64/netboot/yaboot && mv yaboot wheezy/powerpc64
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc64/netboot/initrd.gz && mv initrd.gz wheezy/powerpc64
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc64/netboot/yaboot.conf && mv yaboot.conf wheezy/powerpc64
wget -c -q $mirror/wheezy/main/installer-powerpc/current/images/powerpc64/netboot/boot.msg && mv boot.msg wheezy/powerpc64
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc64/netboot/vmlinux && mv vmlinux squeeze/powerpc64
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc64/netboot/yaboot && mv yaboot squeeze/powerpc64
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc64/netboot/initrd.gz && mv initrd.gz squeeze/powerpc64
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc64/netboot/yaboot.conf && mv yaboot.conf squeeze/powerpc64
wget -c -q $mirror/squeeze/main/installer-powerpc/current/images/powerpc64/netboot/boot.msg  && mv boot.msg squeeze/powerpc64
 


cd ..



for DIST in wheezy lenny sarge etch squeeze; do
      ls -lisa "power/${DIST}"
   for ARCH in powerpc powerpc64; do
 ls -lisa "power/${DIST}/${ARCH}"
yes | cp -Rv power/* LINUX/debian/

 done
done


### Debian - menu

touch pxelinux.cfg/debian-install.cfg
cat >> pxelinux.cfg/debian-install.cfg << EOF
default vesamenu.c32
prompt 0
timeout 0
menu title debian Installers
menu include pxelinux.cfg/graphics.conf
MENU BACKGROUND pxelinux.cfg/background.png
EOF

for DIST in wheezy lenny sarge etch squeeze; do
    for ARCH in i386 amd64 ia64; do
        echo "label Install debian ${DIST} ${ARCH}"
        echo "      menu label debian ${DIST} ${ARCH}"
        echo "      kernel LINUX/debian/${DIST}/${ARCH}/linux"
        echo "      append initrd= LINUX/debian/${DIST}/${ARCH}/initrd.gz ks=http://pxe.sytes.net/answerfiles/kickstart/deb-ks.cfg preseed/url=http://pxe.sytes.net/answerfiles/preseed/deb-preseed.cfg"
        echo""
echo " "
	echo " TEXT HELP"
       echo "  Install Debian Linux  ${DIST} ${ARCH}"
        echo " ENDTEXT"



    done
done >> pxelinux.cfg/debian-install.cfg

for DIST in wheezy squeeze; do
    for ARCH in powerpc powerpc64; do
  echo"device=enet:"
  echo"partition=0"
 
echo" root=/dev/ram"
 
        echo "label Install debian ${DIST} ${ARCH}"
        echo "      menu label debian ${DIST} ${ARCH}"

echo" message=LINUX/debian/${DIST}/${ARCH}/boot.msg"
echo" image=LINUX/debian/${DIST}/${ARCH}/vmlinux"
 
        echo "      kernel LINUX/debian/${DIST}/${ARCH}/vmlinuz"
        echo "      append initrd= LINUX/debian/${DIST}/${ARCH}/initrd.gz "
echo" 	initrd=LINUX/debian/${DIST}/${ARCH}/initrd.gz"
echo" 	initrd-size=14413"
echo" 	read-only"
        echo""
echo " "
	echo " TEXT HELP"
       echo "  Install Debian Linux  ${DIST} ${ARCH}"
        echo " ENDTEXT"

    done
done >> pxelinux.cfg/yaboot.cfg



for DIST in wheezy lenny sarge etch squeeze; do
  ls -lisa "LINUX/debian/${DIST}/${ARCH}"
    for ARCH in i386 amd64; do
      rm -r "LINUX/debian/${DIST}/${ARCH}/pxelinux.0" 
	rm -r "LINUX/debian/${DIST}/${ARCH}/pxelinux.cfg"
rm -r "LINUX/debian/${DIST}/${ARCH}/boot-screens/"
mv power/ tars/
 done 
done

unset mirror 
